package com.power;

import com.power.common.PowerConstant;
import com.power.service.ElectricPowerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author Lijunxiong
 */
@Slf4j
@Component
public class AddElectricPower{

    @Autowired
    private ElectricPowerService electricPowerService;

    @Value("${power.highpowerip}")
    private String highPowerIp;

    @Value("${power.lowpowerip}")
    private String lowPowerIp;

    /**
     *召唤电力数据存入redis
     */
	@Scheduled(fixedRate=60*10000)
	public void power () throws IOException {
	  //乙机房电力数据连接
	  ElectricPower ucHigh = new ElectricPower();
      ucHigh.connect(highPowerIp, PowerConstant.POWER_HIGH);
    /*  //低压电力数据连接
      ElectricPower ucLow = new ElectricPower();
      ucLow.connect(lowPowerIp,PowerConstant.POWER_LOW);*/
	}

    /**
     * 定时存储数据到mongodb
     */
    @Scheduled(cron = "0 */5 * * * ?")
    public void powerMongodbByRedis() {
        electricPowerService.powerMongodbByRedis();
    }
}
